function swap<T, U>(arr: [T, U]): [U, T] { 
  return [arr[1], arr[0]];
}

const s1 = swap([1, "a"]);
console.log(s1);

const s2 = swap([{id:1, name:"jack"}, "a"]);
console.log(s2);

const arr = [1, 2, 3, 4, 5];

function map<T, U>(arr:T[], callback:(e:T, i?:number) => U):U[] { 
  const result = [];
  for (let i = 0; i < arr.length; i++) { 
      const item = arr[i];
      result.push(callback(item, i));
  }
  return result;
}

const t1 = map(arr, (e) => e + 100);
const t2 = map(arr, (e) => `<span>index${e}</span>`);

console.log(t1, t2);